#include <catch2/catch.hpp>

#include "solution.hpp"

using namespace solution_054;

TEST_CASE("054_spiral_matrix", "[054]") {
    SECTION("example 1") {
        std::vector< std::vector<int> > matrix{{1,2,3},{4,5,6},{7,8,9}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1,2,3,6,9,8,7,4,5});
    }

    SECTION("example 2") {
        std::vector< std::vector<int> > matrix{{1,2,3,4},{5,6,7,8},{9,10,11,12}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1,2,3,4,8,12,11,10,9,5,6,7});
    }

    SECTION("example 3") {
        std::vector< std::vector<int> > matrix{{1,2,3}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1,2,3});
    }

    SECTION("example 4") {
        std::vector< std::vector<int> > matrix{{1},{2},{3}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1,2,3});
    }

    SECTION("example 5") {
        std::vector< std::vector<int> > matrix{{1}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1});
    }

    SECTION("example 6") {
        std::vector< std::vector<int> > matrix{{1,2,3},{4,5,6}};
        CHECK(Solution().spiralOrder(matrix) == std::vector{1,2,3,6,5,4});
    }

    SECTION("example 7") {
        std::vector< std::vector<int> > matrix
        {{ 1, 2, 3, 4, 5, 6},
         { 7, 8, 9,10,11,12},
         {13,14,15,16,17,18},
         {19,20,21,22,23,24},
         {25,26,27,28,29,30},
         {31,32,33,34,35,36},
         {37,38,39,40,41,42},};
        std::vector spiral{
         1, 2, 3, 4, 5, 6,
        12,18,24,30,36,
        42,41,40,39,38,37,
        31,25,19,13, 7,
         8, 9,10,11,
        17,23,29,
        35,34,33,32,
        26,20,14,
        15,16,
        22,
        28,27,
        21};
        CHECK(Solution().spiralOrder(matrix) == spiral);
    }
}
